package handler

import (
	"chat/api/request"
	"chat/consts"
	"chat/internal/dao"
	"chat/internal/model"
	"chat/internal/queue"
	"github.com/gin-gonic/gin"
	"net/http"
)

func SendAdminMessage(c *gin.Context) {
	var req request.SendAdminMessageReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(200, gin.H{
			"code":    10000,
			"message": "参数错误",
			"data":    nil,
		})
		return
	}
	message := model.SystemMessage{
		Title:   req.Title,
		Content: req.Content,
	}
	dao.Create(&message)
	queue.PublishPub(consts.WS_EX, &message)
	c.JSON(200, gin.H{
		"code":    http.StatusOK,
		"message": "发送成功",
		"data":    message,
	})
}
